package org.cnbi.web.controller;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.cnbi.service.ISystemService;
import org.cnbi.web.controller.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;


/**
 * 日志处理类
 * Copyright © 2014中国经邦. All rights reserved.
 * @author 龚佳新
 * @date 2014年4月17日下午5:14:42
 * @cnbi-web
 */
@Controller
@RequestMapping("/log")
public class LogController extends BaseController {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(LogController.class);
	@Autowired
	private ISystemService systemService;

	
	

	/**
	 * 日志列表页面跳转
	 * 
	 * @return
	 */
	@RequestMapping(params = "log")
	public ModelAndView log() {
		return new ModelAndView("system/log/logList");
	}

	/**
	 * easyuiAJAX请求数据
	 * @param request
	 * @param response
	 * @param dataGrid
	 */
	/*@RequestMapping(params = "datagrid")
	public void datagrid(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
		CriteriaQuery cq = new CriteriaQuery(TSLog.class, dataGrid);
		String loglevel = request.getParameter("loglevel");
		if (loglevel == null || loglevel.equals("0")) {
		} else {
			cq.eq("loglevel", oConvertUtils.getShort(loglevel));
			cq.add();
		}
		this.systemService.getDataGridReturn(cq, true);
		TagUtil.datagrid(response, dataGrid);
	}*/
	/**
	 * 统计集合页面
	 * 
	 * @return
	 */
	@RequestMapping(params = "statisticTabs")
	public ModelAndView statisticTabs(HttpServletRequest request) {
		return new ModelAndView("system/log/statisticTabs");
	}
	/**
	 * 用户浏览器使用统计图
	 * 
	 * @return
	 */
	@RequestMapping(params = "userBroswer")
	public ModelAndView userBroswer(String reportType, HttpServletRequest request) {
		request.setAttribute("reportType", reportType);
		if("pie".equals(reportType)){
			return new ModelAndView("system/log/userBroswerPie");
		}else if("line".equals(reportType)) {
			return new ModelAndView("system/log/userBroswerLine");
		}
		return new ModelAndView("system/log/userBroswer");
	}

	/**
	 * 报表数据生成
	 * 
	 * @return
	 */
	@RequestMapping(params = "getBroswerBar")
	@ResponseBody
	public List getBroswerBar(HttpServletRequest request,String reportType, HttpServletResponse response) {
	
		return null;
	}

	/**
	 * hightchart导出图片
	 * 
	 * @param request
	 * @param response
	 * @throws IOException
	 */
	//@RequestMapping(params = "export")
//	public void export(HttpServletRequest request, HttpServletResponse response)throws IOException {
//		request.setCharacterEncoding("utf-8");
//		response.setCharacterEncoding("utf-8");
//		String type = request.getParameter("type");
//		String svg = request.getParameter("svg");
//		String filename = request.getParameter("filename");
//
//		filename = filename == null ? "chart" : filename;
//		ServletOutputStream out = response.getOutputStream();
//		try {
//			if (null != type && null != svg) {
//				svg = svg.replaceAll(":rect", "rect");
//				String ext = "";
//				Transcoder t = null;
//				if (type.equals("image/png")) {
//					ext = "png";
//					t = new PNGTranscoder();
//				} else if (type.equals("image/jpeg")) {
//					ext = "jpg";
//					t = new JPEGTranscoder();
//				} else if (type.equals("application/pdf")) {
//					ext = "pdf";
//					t = (Transcoder) new PDFTranscoder();
//				} else if (type.equals("image/svg+xml"))
//					ext = "svg";
//				response.addHeader("Content-Disposition",
//						"attachment; filename=" + new String(filename.getBytes("GBK"),"ISO-8859-1") + "." + ext);
//				response.addHeader("Content-Type", type);
//
//				if (null != t) {
//					TranscoderInput input = new TranscoderInput(
//							new StringReader(svg));
//					TranscoderOutput output = new TranscoderOutput(out);
//
//					try {
//						t.transcode(input, output);
//					} catch (TranscoderException e) {
//						out.print("Problem transcoding stream. See the web logs for more details.");
//						e.printStackTrace();
//					}
//				} else if (ext.equals("svg")) {
//					// out.print(svg);
//					OutputStreamWriter writer = new OutputStreamWriter(out,
//							"UTF-8");
//					writer.append(svg);
//					writer.close();
//				} else
//					out.print("Invalid type: " + type);
//			} else {
//				response.addHeader("Content-Type", "text/html");
//				out.println("Usage:\n\tParameter [svg]: The DOM Element to be converted."+ "\n\tParameter [type]: The destination MIME type for the elment to be transcoded.");
//			}
//		} finally {
//			if (out != null) {
//				out.flush();
//				out.close();
//			}
//		}
//	}

}
